package com.example.hospitalbakcends.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.example.hospitalbakcends.domain.Diagnosis;
import com.example.hospitalbakcends.domain.request.DiagnosisRequest;

import com.example.hospitalbakcends.mapper.DiagnosisMapper;
import com.example.hospitalbakcends.service.DiagnosisService;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author cac_qin
* @description 针对表【diagnosis(诊断)】的数据库操作Service实现
* @createDate 2024-05-21 23:39:22
*/
@Service
public class DiagnosisServiceImpl extends ServiceImpl<DiagnosisMapper, Diagnosis>
    implements DiagnosisService{
    @Resource
    private DiagnosisMapper diagnosisMapper;

    @Override
    public List<Diagnosis> patientDiagnosis(String id, String name){

        QueryWrapper<Diagnosis> diagnosisQueryWrapper =new QueryWrapper<>();
        diagnosisQueryWrapper.eq("patientId",id).eq("patientName",name).eq("isCheck",1);
        return diagnosisMapper.selectList(diagnosisQueryWrapper);
    }

    public List<Diagnosis> getBookDiagnosis(String doctorName){
        QueryWrapper<Diagnosis> diagnosisQueryWrapper =new QueryWrapper<>();
        diagnosisQueryWrapper.eq("doctorName",doctorName).eq("isCheck",0);
        return diagnosisMapper.selectList(diagnosisQueryWrapper);
    };

    @Override
    public List<Diagnosis> getByDoctorName(String doctorName){
        QueryWrapper<Diagnosis> diagnosisQueryWrapper =new QueryWrapper<>();
        diagnosisQueryWrapper.eq("doctorName",doctorName).eq("isCheck",1);
        return diagnosisMapper.selectList(diagnosisQueryWrapper);
    };

    @Override
    public int setIspayByID(String id){
        UpdateWrapper<Diagnosis> updateWrapper=new UpdateWrapper<>();
        updateWrapper.eq("patientId",id).set("isPay",1);
        int result = diagnosisMapper.update(null,updateWrapper);
        if(result==0) {
            return 0;
        }else {
            return 1;
        }
    }

    @Override
    public boolean doDiagnosis(String patientId, String medicine,String price){
        UpdateWrapper<Diagnosis> diagnosisQueryWrapper =new UpdateWrapper<>();
        diagnosisQueryWrapper.eq("patientId",patientId).set("medicines",medicine).set("disMoney",price).set("isCheck",1);
        if(diagnosisMapper.update(null,diagnosisQueryWrapper) == 1) {
            return true;
        }else{
            return false;
        }
    }

    @Override
    public boolean createDignosis(DiagnosisRequest diagnosisRequest){
        Diagnosis diagnosis=new Diagnosis();
        diagnosis.setPatientid(diagnosisRequest.getPatientId());
        diagnosis.setPatientname(diagnosisRequest.getPatientName());
        diagnosis.setDepartment(diagnosisRequest.getDepartMent());
        diagnosis.setDoctorid(diagnosisRequest.getDoctorId());
        diagnosis.setDoctorname(diagnosisRequest.getDoctorName());
        diagnosis.setMedicines(diagnosisRequest.getMedicines());
        diagnosis.setDismoney(diagnosisRequest.getDisMoney());
        diagnosis.setIscheck(diagnosisRequest.getIsCheck());
        boolean saveResult = this.save(diagnosis);
        return saveResult;
    }

}




